import numpy as np
import matplotlib.pyplot as plt

#初始化样本
x = np.random.randint(1, 100, 100)
y = np.array([ i * 10 + np.random.randint(100) for i in x])

#归一化处理
x = x / 100
y = y / 100

#超参数
epoch = 1
#参数
w = 0.1

for _ in range(epoch):
    for i in range(len(x)):
        y_predict = w * x[i]
        loss = y_predict - y[i]
        w -= loss * x[i]

        plt.scatter(x, y)
        plt.plot(x, w * x, color='red')
        plt.show()

print(w)


